package org.mspring.platform.security.service;

import org.mspring.platform.security.dao.RoleResourceDao;
import org.mspring.platform.security.entity.RoleResource;
import org.mspring.platform.security.entity.RoleResourcePK;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Gao Youbo
 * @since 2014年3月8日
 */
@Service
@Transactional
public class RoleResourceService {

    @Autowired
    private RoleResourceDao roleResourceDao;

    /**
     * 创建角色和资源之间的关联关系
     *
     * @param roleId
     * @param resources
     */

    public void createRoleResource(long roleId, String... resources) {
        for (String resource : resources) {
            roleResourceDao.insert(new RoleResource(new RoleResourcePK(roleId, Long.valueOf(resource))));
        }
    }

    /**
     * 删除角色和资源之间的关联关系
     *
     * @param roleId
     * @param resources
     */

    public void deleteRoleResource(long roleId, String... resources) {
        for (String resource : resources) {
            roleResourceDao.delete(new RoleResourcePK(roleId, Long.valueOf(resource)));
        }
    }
}
